﻿using project1113.Wrold;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using project1113;
using project1113.Robot;
using project1113.FSM;
using project1113.SpeechRecoginzer;

namespace project1113.states
{
    internal class InteractionBState:FsmState
    {
        private string _intent;
        
        public InteractionBState(string intent) : base("InteractionB") 
        {
            _intent = intent;
        }
        public override void Init()
        {
            int position = -1;
            int item = -1;
            //Debug.WriteLine("发送指令");\
            string com = string.Empty;
            switch (_intent)
            {
                //实际应该根据槽位查表填参数，但是目前写死了,
                case "hghjg":
                    
                    if (WorldModel.CurrentWorld.SpeechRecoginzer.slotInfoList.Count == 2)
                    {
                        foreach (var slot in WorldModel.CurrentWorld.SpeechRecoginzer.slotInfoList)
                        {
                            switch (slot.SlotName)
                            {
                                case "addr":
                                    position = WorldModel.CurrentWorld.SettingTable.GetLocation(slot.SlotValue).LocationNum;
                                    break;
                                case "item":
                                    item = WorldModel.CurrentWorld.SettingTable.GetItem(slot.SlotValue).ItemNum;
                                    break;
                                default:
                                    break;
                            }
                        }
                        if(position != -1 && item != -1)
                        {
                            com = new Robot.GetItem(position, item).ToJson();
                        }
                        
                    }
                    break;
                case "P2p":
                    if (WorldModel.CurrentWorld.SpeechRecoginzer.slotInfoList.Count == 1)
                    {
                        if (WorldModel.CurrentWorld.SpeechRecoginzer.slotInfoList[0].SlotName == "addr")
                        {
                            position = position = WorldModel.CurrentWorld.SettingTable.GetLocation(WorldModel.CurrentWorld.SpeechRecoginzer.slotInfoList[0].SlotValue).LocationNum;
                        }
                        if(position != -1 && item == -1)
                        {
                            com = new Robot.GetItem(position, item).ToJson();
                        }
                    }
                    break;
                case "Handover":
                    com = new Robot.HandOver().ToJson();
                    break;
                case "LoseHand":
                    com = new Robot.LooseHand().ToJson();
                    break;
                default: 
                    throw new Exception();
            }
            WorldModel.CurrentWorld.Robot.SendCommand(com);
            //设置为远程模式
        }
        public override void DoSomething()
        {
            
            //1.安全检查
            //2.检查意图和繁忙标志位

            //throw new NotImplementedException();
        }
        public override FsmState GetNextState()
        {
          
            return new InteractionAstate();
          
                
            
        } 
    }
}
